using System;
 using System.Collections.Generic;
 using System.Text;
 using System.Data;
 using System.Data.SqlClient;
 using MinhTam.DataAccess.Web;
//───────────────────────────────────────────────────────────────────────────────────────
 namespace MinhTam.Objects
  { 
 public class DIA_DIEM_DU_LICH:  SQLConnectWeb { 
 public static string sTableName= "DIA_DIEM_DU_LICH"; 
   public string DIA_DIEM_ID;
   public string TEN_DIA_DIEM;
   public string DIA_CHI;
   public string TINH_THANH;
   public string SO_DIEN_THOAI;
   public string MO_TA;
   public string MAP_URL;
   #region DataColumn Name ;
 public static  string cl_DIA_DIEM_ID="DIA_DIEM_ID" ;
 public static  string cl_TEN_DIA_DIEM="TEN_DIA_DIEM" ;
 public static  string cl_DIA_CHI="DIA_CHI" ;
 public static  string cl_TINH_THANH="TINH_THANH" ;
 public static  string cl_SO_DIEN_THOAI="SO_DIEN_THOAI" ;
 public static  string cl_MO_TA="MO_TA" ;
 public static  string cl_MAP_URL="MAP_URL" ;
 #endregion;
//───────────────────────────────────────────────────────────────────────────────────────
       public DIA_DIEM_DU_LICH() {}
//───────────────────────────────────────────────────────────────────────────────────────
       public DIA_DIEM_DU_LICH(
         string sDIA_DIEM_ID,
         string sTEN_DIA_DIEM,
         string sDIA_CHI,
         string sTINH_THANH,
         string sSO_DIEN_THOAI,
         string sMO_TA,
         string sMAP_URL){
         this.DIA_DIEM_ID= sDIA_DIEM_ID;
         this.TEN_DIA_DIEM= sTEN_DIA_DIEM;
         this.DIA_CHI= sDIA_CHI;
         this.TINH_THANH= sTINH_THANH;
         this.SO_DIEN_THOAI= sSO_DIEN_THOAI;
         this.MO_TA= sMO_TA;
         this.MAP_URL= sMAP_URL;
}
//───────────────────────────────────────────────────────────────────────────────────────
       public static DIA_DIEM_DU_LICH Create_DIA_DIEM_DU_LICH ( string sDIA_DIEM_ID  ){
    DataTable dt=SearchByDIA_DIEM_ID(sDIA_DIEM_ID) ;
    if(dt!=null && dt.Rows.Count>0) 
      return new DIA_DIEM_DU_LICH(dt,0);
      return null;
}
//───────────────────────────────────────────────────────────────────────────────────────
   private static string s_Select()
    {
   return " SELECT T.* FROM DIA_DIEM_DU_LICH AS T";
    }
//───────────────────────────────────────────────────────────────────────────────────────
 public DIA_DIEM_DU_LICH( DataTable table,int pos)
{
         this.DIA_DIEM_ID= table.Rows[pos]["DIA_DIEM_ID"].ToString();
         this.TEN_DIA_DIEM= table.Rows[pos]["TEN_DIA_DIEM"].ToString();
         this.DIA_CHI= table.Rows[pos]["DIA_CHI"].ToString();
         this.TINH_THANH= table.Rows[pos]["TINH_THANH"].ToString();
         this.SO_DIEN_THOAI= table.Rows[pos]["SO_DIEN_THOAI"].ToString();
         this.MO_TA= table.Rows[pos]["MO_TA"].ToString();
         this.MAP_URL= table.Rows[pos]["MAP_URL"].ToString();
}
//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByDIA_DIEM_ID(string sDIA_DIEM_ID)
{
          string sqlSelect= s_Select()+ " WHERE DIA_DIEM_ID  ="+ sDIA_DIEM_ID + ""; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByDIA_DIEM_ID(string sDIA_DIEM_ID,string sMatch)
{
          string sqlSelect= s_Select()+ " WHERE DIA_DIEM_ID"+ sMatch +sDIA_DIEM_ID + ""; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByTEN_DIA_DIEM(string sTEN_DIA_DIEM)
{
          string sqlSelect= s_Select()+ " WHERE TEN_DIA_DIEM  Like N'%"+ sTEN_DIA_DIEM + "%'"; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByDIA_CHI(string sDIA_CHI)
{
          string sqlSelect= s_Select()+ " WHERE DIA_CHI  Like N'%"+ sDIA_CHI + "%'"; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByTINH_THANH(string sTINH_THANH)
{
          string sqlSelect= s_Select()+ " WHERE TINH_THANH  ="+ sTINH_THANH + ""; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByTINH_THANH(string sTINH_THANH,string sMatch)
{
          string sqlSelect= s_Select()+ " WHERE TINH_THANH"+ sMatch +sTINH_THANH + ""; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchBySO_DIEN_THOAI(string sSO_DIEN_THOAI)
{
          string sqlSelect= s_Select()+ " WHERE SO_DIEN_THOAI  Like N'%"+ sSO_DIEN_THOAI + "%'"; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByMO_TA(string sMO_TA)
{
          string sqlSelect= s_Select()+ " WHERE MO_TA  Like '%"+ sMO_TA + "%'"; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable SearchByMAP_URL(string sMAP_URL)
{
          string sqlSelect= s_Select()+ " WHERE MAP_URL  Like '%"+ sMAP_URL + "%'"; 
          DataTable dt=GetTable(sqlSelect,sTableName) ;
          return dt; 
 }//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable Search( string sDIA_DIEM_ID
            , string sTEN_DIA_DIEM
            , string sDIA_CHI
            , string sTINH_THANH
            , string sSO_DIEN_THOAI
            , string sMO_TA
            , string sMAP_URL
            )
 {
       string sqlselect=s_Select() + " WHERE" ;
      if (sDIA_DIEM_ID!=null && sDIA_DIEM_ID!="") 
            sqlselect +=" AND DIA_DIEM_ID =" + sDIA_DIEM_ID ;
      if (sTEN_DIA_DIEM!=null && sTEN_DIA_DIEM!="") 
            sqlselect +=" AND TEN_DIA_DIEM LIKE N'%" + sTEN_DIA_DIEM +"%'" ;
      if (sDIA_CHI!=null && sDIA_CHI!="") 
            sqlselect +=" AND DIA_CHI LIKE N'%" + sDIA_CHI +"%'" ;
      if (sTINH_THANH!=null && sTINH_THANH!="") 
            sqlselect +=" AND TINH_THANH =" + sTINH_THANH ;
      if (sSO_DIEN_THOAI!=null && sSO_DIEN_THOAI!="") 
            sqlselect +=" AND SO_DIEN_THOAI LIKE N'%" + sSO_DIEN_THOAI +"%'" ;
      if (sMO_TA!=null && sMO_TA!="") 
            sqlselect +=" AND MO_TA LIKE '%" + sMO_TA +"%'" ;
      if (sMAP_URL!=null && sMAP_URL!="") 
            sqlselect +=" AND MAP_URL LIKE '%" + sMAP_URL +"%'" ;
   sqlselect=sqlselect.Replace("WHERE AND","WHERE");
   int n=sqlselect.IndexOf("WHERE");
   if(n==sqlselect.Length -5) sqlselect=sqlselect.Remove(n,5) ;
   return GetTable(sqlselect,sTableName);
}
//───────────────────────────────────────────────────────────────────────────────────────
 public static DIA_DIEM_DU_LICH Insert_Object(
string  sTEN_DIA_DIEM
            ,string  sDIA_CHI
            ,string  sTINH_THANH
            ,string  sSO_DIEN_THOAI
            ,string  sMO_TA
            ,string  sMAP_URL
            ) 
 { 
              string tem_sTEN_DIA_DIEM=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sTEN_DIA_DIEM,"nvarchar");
              string tem_sDIA_CHI=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sDIA_CHI,"nvarchar");
              string tem_sTINH_THANH=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sTINH_THANH,"int");
              string tem_sSO_DIEN_THOAI=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sSO_DIEN_THOAI,"varchar");
              string tem_sMO_TA=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sMO_TA,"ntext");
              string tem_sMAP_URL=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sMAP_URL,"ntext");

             string sqlSave=" INSERT INTO DIA_DIEM_DU_LICH("+
                   "TEN_DIA_DIEM," 
        +                   "DIA_CHI," 
        +                   "TINH_THANH," 
        +                   "SO_DIEN_THOAI," 
        +                   "MO_TA," 
        +                   "MAP_URL) VALUES("
 +tem_sTEN_DIA_DIEM+","
 +tem_sDIA_CHI+","
 +tem_sTINH_THANH+","
 +tem_sSO_DIEN_THOAI+","
 +tem_sMO_TA+","
 +tem_sMAP_URL +")";
             bool OK = Exec(sqlSave)>=1?true:false;
           if (OK) 
           { 
          DIA_DIEM_DU_LICH newDIA_DIEM_DU_LICH= new DIA_DIEM_DU_LICH();
                 newDIA_DIEM_DU_LICH.DIA_DIEM_ID=GetTable( " SELECT TOP 1 DIA_DIEM_ID FROM DIA_DIEM_DU_LICH ORDER BY DIA_DIEM_ID DESC ").Rows[0][0].ToString();
              newDIA_DIEM_DU_LICH.TEN_DIA_DIEM=sTEN_DIA_DIEM;
              newDIA_DIEM_DU_LICH.DIA_CHI=sDIA_CHI;
              newDIA_DIEM_DU_LICH.TINH_THANH=sTINH_THANH;
              newDIA_DIEM_DU_LICH.SO_DIEN_THOAI=sSO_DIEN_THOAI;
              newDIA_DIEM_DU_LICH.MO_TA=sMO_TA;
              newDIA_DIEM_DU_LICH.MAP_URL=sMAP_URL;
            return newDIA_DIEM_DU_LICH; 
           } 
           else return null ;
}
//───────────────────────────────────────────────────────────────────────────────────────
public bool  Save_Object(string sTEN_DIA_DIEM
                ,string sDIA_CHI
                ,string sTINH_THANH
                ,string sSO_DIEN_THOAI
                ,string sMO_TA
                ,string sMAP_URL
                ) 
 { 
              string tem_sTEN_DIA_DIEM=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sTEN_DIA_DIEM,"nvarchar");
              string tem_sDIA_CHI=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sDIA_CHI,"nvarchar");
              string tem_sTINH_THANH=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sTINH_THANH,"int");
              string tem_sSO_DIEN_THOAI=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sSO_DIEN_THOAI,"varchar");
              string tem_sMO_TA=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sMO_TA,"ntext");
              string tem_sMAP_URL=MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(sMAP_URL,"ntext");

 string sqlSave=" UPDATE DIA_DIEM_DU_LICH SET "+"TEN_DIA_DIEM ="+tem_sTEN_DIA_DIEM+","
 +"DIA_CHI ="+tem_sDIA_CHI+","
 +"TINH_THANH ="+tem_sTINH_THANH+","
 +"SO_DIEN_THOAI ="+tem_sSO_DIEN_THOAI+","
 +"MO_TA ="+tem_sMO_TA+","
 +"MAP_URL ="+tem_sMAP_URL+" WHERE DIA_DIEM_ID="+MinhTam.DataAccess.Web.SQLToolWeb.GetSaveValue(this.DIA_DIEM_ID,"int identity");;
              bool OK = Exec(sqlSave)>=1?true:false;
           if (OK) 
           { 
                this.TEN_DIA_DIEM=sTEN_DIA_DIEM;
                this.DIA_CHI=sDIA_CHI;
                this.TINH_THANH=sTINH_THANH;
                this.SO_DIEN_THOAI=sSO_DIEN_THOAI;
                this.MO_TA=sMO_TA;
                this.MAP_URL=sMAP_URL;
           } 
 return OK;  }
//───────────────────────────────────────────────────────────────────────────────────────
 #region Update DataColumn  
 public bool Update_DIA_DIEM_ID(string sDIA_DIEM_ID)
{
    string sqlSave= " UPDATE DIA_DIEM_DU_LICH SET DIA_DIEM_ID='"+ sDIA_DIEM_ID+ "' WHERE DIA_DIEM_ID='"+ this.DIA_DIEM_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 if(OK)
 {
    this.DIA_DIEM_ID=sDIA_DIEM_ID;
 }
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public bool Update_TEN_DIA_DIEM(string sTEN_DIA_DIEM)
{
    string sqlSave= " UPDATE DIA_DIEM_DU_LICH SET TEN_DIA_DIEM='N"+ sTEN_DIA_DIEM+ "' WHERE DIA_DIEM_ID='"+ this.DIA_DIEM_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 if(OK)
 {
    this.TEN_DIA_DIEM=sTEN_DIA_DIEM;
 }
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public bool Update_DIA_CHI(string sDIA_CHI)
{
    string sqlSave= " UPDATE DIA_DIEM_DU_LICH SET DIA_CHI='N"+ sDIA_CHI+ "' WHERE DIA_DIEM_ID='"+ this.DIA_DIEM_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 if(OK)
 {
    this.DIA_CHI=sDIA_CHI;
 }
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public bool Update_TINH_THANH(string sTINH_THANH)
{
    string sqlSave= " UPDATE DIA_DIEM_DU_LICH SET TINH_THANH='"+ sTINH_THANH+ "' WHERE DIA_DIEM_ID='"+ this.DIA_DIEM_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 if(OK)
 {
    this.TINH_THANH=sTINH_THANH;
 }
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public bool Update_SO_DIEN_THOAI(string sSO_DIEN_THOAI)
{
    string sqlSave= " UPDATE DIA_DIEM_DU_LICH SET SO_DIEN_THOAI='N"+ sSO_DIEN_THOAI+ "' WHERE DIA_DIEM_ID='"+ this.DIA_DIEM_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 if(OK)
 {
    this.SO_DIEN_THOAI=sSO_DIEN_THOAI;
 }
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public bool Update_MO_TA(string sMO_TA)
{
    string sqlSave= " UPDATE DIA_DIEM_DU_LICH SET MO_TA='"+ sMO_TA+ "' WHERE DIA_DIEM_ID='"+ this.DIA_DIEM_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 if(OK)
 {
    this.MO_TA=sMO_TA;
 }
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public bool Update_MAP_URL(string sMAP_URL)
{
    string sqlSave= " UPDATE DIA_DIEM_DU_LICH SET MAP_URL='"+ sMAP_URL+ "' WHERE DIA_DIEM_ID='"+ this.DIA_DIEM_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 if(OK)
 {
    this.MAP_URL=sMAP_URL;
 }
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 #endregion
 #region Update DataColumn  Static 
 public static bool Update_TEN_DIA_DIEM(string sTEN_DIA_DIEM,string s_DIA_DIEM_ID)
{
  string sqlSave= " UPDATE DIA_DIEM_DU_LICH SET TEN_DIA_DIEM='N"+sTEN_DIA_DIEM+"' WHERE DIA_DIEM_ID='"+ s_DIA_DIEM_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public static bool Update_DIA_CHI(string sDIA_CHI,string s_DIA_DIEM_ID)
{
  string sqlSave= " UPDATE DIA_DIEM_DU_LICH SET DIA_CHI='N"+sDIA_CHI+"' WHERE DIA_DIEM_ID='"+ s_DIA_DIEM_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public static bool Update_TINH_THANH(string sTINH_THANH,string s_DIA_DIEM_ID)
{
  string sqlSave= " UPDATE DIA_DIEM_DU_LICH SET TINH_THANH='"+sTINH_THANH+"' WHERE DIA_DIEM_ID='"+ s_DIA_DIEM_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public static bool Update_SO_DIEN_THOAI(string sSO_DIEN_THOAI,string s_DIA_DIEM_ID)
{
  string sqlSave= " UPDATE DIA_DIEM_DU_LICH SET SO_DIEN_THOAI='N"+sSO_DIEN_THOAI+"' WHERE DIA_DIEM_ID='"+ s_DIA_DIEM_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public static bool Update_MO_TA(string sMO_TA,string s_DIA_DIEM_ID)
{
  string sqlSave= " UPDATE DIA_DIEM_DU_LICH SET MO_TA='"+sMO_TA+"' WHERE DIA_DIEM_ID='"+ s_DIA_DIEM_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
 public static bool Update_MAP_URL(string sMAP_URL,string s_DIA_DIEM_ID)
{
  string sqlSave= " UPDATE DIA_DIEM_DU_LICH SET MAP_URL='"+sMAP_URL+"' WHERE DIA_DIEM_ID='"+ s_DIA_DIEM_ID+"' ";
 bool OK=Exec(sqlSave)>=1?true:false;
 return OK;
}
//───────────────────────────────────────────────────────────────────────────────────────
#endregion
//───────────────────────────────────────────────────────────────────────────────────────
 public static DataTable GetTableAll() 
 {
       return  GetTableAll(null, null);
 }
public static DataTable GetTableAll(string sWhere, params string[] orderFields)
{
   string sqlSelect = " SELECT * FROM DIA_DIEM_DU_LICH";
   if (!string.IsNullOrEmpty(sWhere))
      sqlSelect += " where " + sWhere; 
   string order = "";
   if (orderFields != null && orderFields.Length > 0)
     order = string.Join(",", orderFields);
   if (order != "")
      sqlSelect += " ORDER BY " + order;
   return GetTable(sqlSelect,sTableName);
}
//───────────────────────────────────────────────────────────────────────────────────────
//───────────────────────────────────────────────────────────────────────────────────────
public static DataTable GetTableFields(string sWhere, string[] orderFields, params string[] fields)
{
 string field = "";
 if (fields != null && fields.Length > 0)
    field = string.Join(",", fields);
 else field = "*";
 string sqlSelect = string.Format(" SELECT {0} FROM {1} ", field, "DIA_DIEM_DU_LICH");
 if (!string.IsNullOrEmpty(sWhere))
    sqlSelect += " where " + sWhere;
 string order = "";
 if (orderFields != null && orderFields.Length > 0)
    order = string.Join(",", orderFields);
 if (order != "")
    sqlSelect += " ORDER BY " + order;
 return GetTable(sqlSelect,sTableName);
 }
 public static DataTable GetTableFields(params string[] fields)
 {
    return GetTableFields(null, null, fields);
 }
 public static DataTable GetTableFields(string[] orderFields, params string[] fields)
 {
    return GetTableFields(null, orderFields, fields);
 }
//───────────────────────────────────────────────────────────────────────────────────────
   private static DataTable dt_DIA_DIEM_DU_LICH;
   public static bool Change_dt_DIA_DIEM_DU_LICH = true;
   public static bool AllowAutoChange = true;
   public static DataTable get_DIA_DIEM_DU_LICH()
   {
   if (dt_DIA_DIEM_DU_LICH == null || Change_dt_DIA_DIEM_DU_LICH == true)
     {
   dt_DIA_DIEM_DU_LICH = GetTableAll();
         Change_dt_DIA_DIEM_DU_LICH = true && AllowAutoChange ;
     }
     return dt_DIA_DIEM_DU_LICH;
   }
   //───────────────────────────────────────────────────────────────────────────────────────
}  
 } 
